﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSite.App_Data;
using WebSite.Models;
using WebSite.App_Code;
using Excel = Microsoft.Office.Interop.Excel;
using System.Web.Configuration;

namespace WebSite.Controllers
{
    [HandleError]
    public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            Session.Remove("Home.Index.UploadReview");

            IndexModel M = new IndexModel();
            M.U = this.CurrentUser;

            M.BudgetList = M.GetBudgetList();

            return View("Index", M);
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Login()
        {
            CurrentUserClear();

            return View("Login");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Login(FormCollection collection)
        {
            CurrentUserClear();

            UserItem user = HomeModel.Login(collection["user_name"], collection["user_password"]);

            if (user == null)
            {
                ViewData["DB.Operation.Result"] = "用户不存在,或者密码错误";
                return Login();
            }
            else
            {
                CurrentUser = user;

                WirteLog(L_LogType.COM_Login, this.CurrentUser.User.Guid, "登录成功");

                return Redirect("/Home/Index");
            }
        }

        public ActionResult Error()
        {
            return View("Error");
        }
    }
}
